package com.aaa.car.controller;

import com.aaa.car.entity.TbCar;
import com.aaa.car.entity.TbCarTypeConfigDetails;
import com.aaa.car.service.TbCarService;
import com.aaa.common.bo.CouponHistory;
import com.aaa.common.constant.ExceptionConstant;
import com.aaa.common.constant.ReturnCode;
import com.aaa.common.util.CustomException;
import com.aaa.common.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 车辆表(TbCar)表控制层
 *
 * @author makejava
 * @since 2020-11-20 23:10:08
 */
@RestController
@RequestMapping("tbCar")
public class TbCarController {
    /**
     * 服务对象
     */
    @Resource
    private TbCarService tbCarService;

    /**
     * 多条件查询车辆基本信息
     * @param carId
     * @return
     */
    @GetMapping("selectOne")
    public TbCar selectOne(@RequestParam("carId") Integer carId) {
        if(carId==null){
            throw new CustomException(ExceptionConstant.INVALID_ARGUMENT.getErrorCode(),
                    ExceptionConstant.INVALID_ARGUMENT.getErrorMessage());
        }
       return tbCarService.queryById(carId);
    }
    /**
     * 多条件查询车辆基本信息
     * @param pageNo
     * @param pageSize
     * @param carTypeName
     * @return
     */
    @GetMapping("queryAllCar")
    public Result queryAllCar(Integer pageNo,
                              Integer pageSize,
                              String carTypeName,
                              String brandname,
                              String shopname,
                              String priceOrder,
                              Integer state
    ){
        if(pageNo==null||pageSize==null){
            throw new CustomException(ExceptionConstant.INVALID_ARGUMENT.getErrorCode(),
                    ExceptionConstant.INVALID_ARGUMENT.getErrorMessage());
        }
        return tbCarService.queryAllCar(pageNo,pageSize,carTypeName,brandname,shopname,priceOrder,state);
    }

    /**
     * 修改车辆信息
     * @param tbCar
     * @return
     */
    @PutMapping("update")
    public Result update(@RequestBody TbCar tbCar){
        //当ID空为时抛出自定义异常
        if (tbCar.getId()==null) {
            throw new CustomException(ExceptionConstant.ID_NOT_NULL.getErrorCode(),
                    ExceptionConstant.ID_NOT_NULL.getErrorMessage());
        }
        //返回成功
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(), this.tbCarService.update(tbCar));
    }
}